/********************************************
 * a simple hello world program for windows *
 ********************************************/

#include <windows.h>

static char szWndClassName[] = "CHelloWorld" ;

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch (message)
   {
      case WM_PAINT:
      {
         HDC hdc;
         PAINTSTRUCT ps;

         hdc = BeginPaint( hwnd, &ps );
         TextOut(hdc, 0, 0, "Hello World", 11);
         EndPaint( hwnd, &ps );
         return 0;
      }

      case WM_DESTROY:
      {
         PostQuitMessage (0) ;
         return 0;
      }

      default:
         return DefWindowProc (hwnd, message, wParam, lParam) ;
   }
}

int InitApplication(HINSTANCE hInstCurr)
{
   WNDCLASS wc;   /* window class */

   wc.style         = CS_HREDRAW | CS_VREDRAW ;
   wc.lpfnWndProc   = (WNDPROC)WndProc ;
   wc.cbClsExtra    = 0 ;
   wc.cbWndExtra    = 0 ;
   wc.hInstance     = hInstCurr ;
   wc.hIcon         = NULL;
   wc.hCursor       = LoadCursor(0,IDC_ARROW);
   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
   wc.lpszMenuName  = NULL;
   wc.lpszClassName = szWndClassName;
   return RegisterClass(&wc);
}


int InitInstance(HINSTANCE hInstCurr, int nCmdShow)
{
   HWND hWnd;

   hWnd = CreateWindow(szWndClassName,
      "Hello World",
      WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      NULL,
      NULL,
      hInstCurr,
      NULL);

   if (hWnd)
   {
      ShowWindow(hWnd, nCmdShow);
      UpdateWindow(hWnd);
      return (TRUE);
   }
   return FALSE;
}


int WinMain (HINSTANCE hInstCurr, HINSTANCE hInstPrev, LPSTR lpszCmd, int nCmdShow)
{
   MSG msg ;

   if (!hInstPrev)
      if (!InitApplication(hInstCurr)) return 0;

   if (!InitInstance(hInstCurr, nCmdShow)) return 0;

   while (GetMessage (&msg, NULL, 0, 0))
   {
      TranslateMessage (&msg) ;
      DispatchMessage (&msg) ;
   }
   return msg.wParam ;
}
